<template>
  <div class="app-container" id="order">
    <div style="overflow:hidden">
      <el-form style="float:left">
        <el-form-item label="手机号" label-width="60px" class="input">
          <el-input v-model="form.phoneNum" placeholder="请输入手机号"></el-input>
        </el-form-item>
        <el-form-item label="请选择渠道" :label-width="formLabelWidth" class="input">
          <el-select v-model="form.retailerName" placeholder="请选择"  @change="getOrderList" >
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.retailersName"
              :value="item.retailersName">
            </el-option>
          </el-select>
        </el-form-item>
        <!--<el-form-item label="渠道名称" :label-width="formLabelWidth" class="input">-->
          <!--<el-input v-model="form.retailerName" placeholder="请输入渠道名称"></el-input>-->
        <!--</el-form-item>-->
        <el-form-item label="时间查询" :label-width="formLabelWidth" class="input">
            <el-date-picker
              v-model="dateArr"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
        </el-form-item>
      </el-form>
      <el-button type="primary" icon="el-icon-search" style="float:left;margin-left:10px" @click="getOrderList">查询</el-button>
      <el-button type="danger" icon="el-icon-download" style="float:left;margin-left:10px" @click="orderExcel">导出excel</el-button>
    </div>
    <el-table :data="orderData" border style="width: 100%" class="actTable">
      <el-table-column prop="orderId"            label="订单ID"         min-width="180"></el-table-column>
      <el-table-column prop="userPhoneNum"       label="手机号"         width="120"></el-table-column>
      <el-table-column prop="retailerName"       label="渠道来源"       width="100"></el-table-column>
      <el-table-column prop="companyName"        label="P2P商家"       min-width="80"></el-table-column>
      <el-table-column prop="projectType"        label="投资项目"       width="80"></el-table-column>
      <el-table-column prop="investmentTerm"     label="投资期限"       width="80"></el-table-column>
      <el-table-column prop="createTime"         label="投资时间"       min-width="100"></el-table-column>
      <el-table-column prop="orderAmount"        label="投资金额"       width="80"></el-table-column>
      <el-table-column prop="rebateTime"         label="返利时间"       min-width="120"></el-table-column>
      <el-table-column prop="rebateAmonut"       label="返利金额"       width="100"></el-table-column>
      <el-table-column prop="marketAmount"       label="营销奖励"       width="80"></el-table-column>
      <el-table-column prop="investType"         label="类型"          width="80">
        <template slot-scope="scope">
          <span>{{scope.row.investType===0?'首投':'复投' }}</span>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="curPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="size">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
import { api, orderList } from 'api/order'
import { retailersList } from 'api/retailers'
export default {
  data() {
    return {
      options: [],
      orderData: [],
      showDialog: false,
      activityId: '',
      form: {
        phoneNum: '',
        retailerName: ''
      },
      dateArr: [],
      pageSize: 10,
      curPage: 1,
      size: 0,
      formLabelWidth: '120px'
    }
  },
  created() {
    this.getOnlineList()
    this.getOrderList()
  },
  methods: {
    async getOnlineList() {
      const parm = {
        pageSize: 1000,
        curPage: 0
      }
      try {
        let back = await retailersList(parm)
        back = back.data
        if (back.resultCode === '200') {
          this.options = back.result
        }
      } catch (err) {
        this.$alert('请求出错', '提示')
      }
    },
    async getOrderList() {
      const parm = { ...this.form }
      parm.pageSize = this.pageSize
      parm.curPage = this.curPage - 1
      console.log(this.dateArr)
      if (this.dateArr == null || this.dateArr.length === 0) {
        parm.startTime = ''
        parm.endTime = ''
      } else {
        parm.startTime = moment(this.dateArr[0]).format('YYYY-MM-DD')
        parm.endTime = moment(this.dateArr[1]).format('YYYY-MM-DD')
      }
      try {
        let back = await orderList(parm)
        back = back.data
        if (back.resultCode === '200') {
          this.orderData = back.result
          this.size = back.size
        }
      } catch (err) {
        this.$alert('请求出错', '提示')
      }
    },
    orderExcel() {
      window.location.href = api.orderExcel
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getOrderList()
    },
    handleCurrentChange(val) {
      this.curPage = val
      this.getOrderList()
    }
  }
}
</script>
<style scoped lang="scss">
  #order {
    .actTable{
      margin-top:20px;
    }
    .banner {
      width: 200px;
    }
    .input{
      float: left;
    }
  }
  .block{
    float:right;
    margin-top:15px;
  }
</style>
